using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

namespace BruteMerge.Merger
{
    internal static class Extensions
    {
        public static IEnumerable<T> Concat<T>(this IEnumerable<T> source, T ex)
        {
            foreach (var element in source)
            {
                yield return element;
            }

            yield return ex;
        }

        public static TAttribute GetAttribute<TAttribute>(this ICustomAttributeProvider member)
            where TAttribute : Attribute
        {
            return (TAttribute) member.GetCustomAttributes(typeof (TAttribute), false).SingleOrDefault();
        }

        /// <summary>
        /// Maybe monad LOL
        /// </summary>
        public static void Do<T>(this T obj, Action<T> action ) where T : class
        {
            if (obj != null)
            {
                action(obj);
            }
        }


        public static MemoryStream CreateStream(this byte[] array)
        {
            return new MemoryStream(array);
        }
    }
}